<?php

namespace app\manage\controller;
use think\Db;
use think\Request;

class Statistics extends Base
{
    //学员列表
    public function salesmanincomeStatisticList(Request $request){
       
        $list = Db("charge")->where(function($query){
            //等级
            $level = $this->request->param('admin_auth')['level'];
            if($level == 4){//业务员
                $query->where("account_id",$this->request->param('admin_auth')['auth_admin_id']);
            }
            if($level != 1 && $level != 3){
                //公司id
                $cid = $this->request->param('admin_auth')['cid'];
                $query->where("cid",$cid);
            }
            $account_name = input("account_name");
            if(!empty($account_name)){
                $query->where("account_name",'like','%'.$account_name.'%');
            }
            $query->where("status",3);
            //创建时间区间
            $start = input("start",'');
            $end = input("end",'');
            if(!empty($start) && !empty($end)){
                $query->where("create_time",'between',[$start,$end]);
            }
        })->field("account_id as id,MAX(create_time) as create_time,(select user_name from mm_students where mm_students.order_sn = students_sn ) as user_name,(SELECT b.company_name from mm_admin as a LEFT JOIN mm_company as b on a.cid = b.id where a.id = account_id) as company_name,account_name,agreement_price,sum(submit_price) as all_submit_price,(agreement_price -  sum(submit_price)) as all_overdue_price")->group("account_id")->paginate(15);
        
        $this->assign("data",$request->param());
        $this->assign("list",$list);
        $page = $list->render();
        $this->assign('page', $page);
        return view("salesmanincomeStatisticList");
    }








}